<!DOCTYPE html>
<html lang="zh-cmn-Hans">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>拓深科技</title>
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <link href="assets/bootstrap/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="assets/font-awesome/css/font-awesome.min.css" rel="stylesheet"/>
    <link href="assets/ionicons-2.0.1/css/ionicons.min.css" rel="stylesheet"/>
    <link href="assets/plugins/daterangepicker/daterangepicker-bs3.css" rel="stylesheet" />
    <link href="assets/plugins/select2/select2.min.css" rel="stylesheet"/>
    <link href="assets/DataTables-1.10.11/media/css/dataTables.bootstrap.min.css" rel="stylesheet"/>
    <link href="assets/AdminLTE/dist/css/AdminLTE.min.css" rel="stylesheet"/>
    <link href="assets/AdminLTE/dist/css/skins/_all-skins.min.css" rel="stylesheet"/>
    <link href="assets/images/log.ico" rel="shortcut icon">
    <link href="assets/ipicture/css/iPicture_location.css" rel="stylesheet" media="screen"/>
    <script src="js/alert_check.js"></script>
</head>
<body class="hold-transition skin-red sidebar-mini">
<div class="wrapper">
    <header id="top_header" class="main-header">
        <a href="main_page.html" class="logo">
            <span class="logo-mini"><b>T</b>pson</span>
            <span class="logo-lg"><b>T</b>PSON</span>
        </a>
        <nav class="navbar navbar-static-top" role="navigation">
            <a href="#" class="sidebar-toggle" data-toggle="offcanvas" role="button">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </a>
            <div class="navbar-custom-menu">
                <ul class="nav navbar-nav">
                    <li class="dropdown user user-menu">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                            <span class="hidden-xs">Administrator</span>
                        </a>
                    </li>
                </ul>
            </div>
        </nav>
    </header>
    <!--顶部导航栏结束-->
    <!--右侧导航栏开始-->
    <aside class="main-sidebar">
        <!-- sidebar: style can be found in sidebar.less -->
        <section class="sidebar">
            <!-- Sidebar user panel -->
            <!-- sidebar menu: : style can be found in sidebar.less -->
            <ul id="side_bar" class="sidebar-menu">
                <li class="header">导航栏</li>
                <li class="treeview">
                    <a href="main_page.html">
                        <i class="fa fa-dashboard text-red"></i>
                        <span>主页</span>
                    </a>
                </li>

                <li class="treeview active">
                    <a href="alert_log.html">
                        <i class="fa fa-warning text-red"></i>
                        <span>报警记录</span>
                    </a>
                </li>
                <li class="treeview">
                    <a href="map_show.html">
                        <i class="fa fa-map-marker text-red"></i>
                        <span>地图展示</span>
                    </a>
                </li>
                <li class="treeview">
                    <a href="#">
                        <i class="fa fa-cog text-red"></i>
                        <span>设备管理</span>
                        <i class="fa fa-angle-left pull-right"></i>
                    </a>
                    <ul class="treeview-menu">
                        <!--<li><a href="router_status.html"><i class="fa fa-circle-o text-yellow"></i>设备状态 </a> </li>-->
                        <li><a href="router_config.html"><i class="fa fa-circle-o text-yellow"></i>设备配置 </a> </li>
                    </ul>
                </li>
                <li class="treeview">
                    <a href="#">
                        <i class="fa fa-chain-broken text-red"></i>
                        <span>监测点配置</span>
                        <i class="fa fa-angle-left pull-right"></i>
                    </a>
                    <ul class="treeview-menu">
                        <li><a href="monitor_config_map_config.html"><i class="fa fa-circle-o text-yellow"></i>地图配置 </a> </li>
                        <li><a href="monitor_config_sensor_type_input.html"><i class="fa fa-circle-o text-yellow"></i>传感器类别设置 </a> </li>
                        <li><a href="monitor_config_monitor_input.html"><i class="fa fa-circle-o text-yellow"></i>监测点配置 </a> </li>
                        <li><a href="monitor_config_export.html"><i class="fa fa-circle-o text-yellow"></i>数据导入导出 </a> </li>
                    </ul>
                </li>

                <li id="sys_log" class="treeview">
                    <a href="show_log.html">
                        <i class="fa fa-files-o text-red"></i>
                        <span>系统日志</span>
                    </a>
                </li>
            </ul>
        </section>
        <!-- /.sidebar -->
    </aside>
    <!--右侧导航栏结束-->
    <!--内容区开始-->
    <div class="content-wrapper">
        <section class="content-header">
            <h1>
                <b>报警记录</b>
            </h1>
            <ol class="breadcrumb">
                <li><a href="main_page.html"><i class="fa fa-dashboard"></i> 主页</a></li>
                <li><a href="alert_log.html"><i class="fa fa-warning"></i> 报警记录</a> </li>
            </ol>
        </section>

        <section class="invoice">
            <div class="row">
                <div class="box box-warning ">
                    <div class="box-header">
                        <h4 class="box-title"><b>报警记录列表</b></h4>
                    </div>
                    <div class="box-body">
                        <table id="alert_table" class="table table-bordered table-striped">
                            <thead>
                            <tr>
                                <th>报警ID</th>
                                <th>传感器名称</th>
                                <th>报警时间</th>
                                <th>所属设备</th>
                                <th>报警位置</th>
                                <th>报警类型</th>
                                <th>报警回路号</th>
                                <th>报警状态</th>
                            </tr>
                            </thead>
                            <tbody id="alert_table_body">

                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </section>
        <div class="clearfix"></div>
    </div>

    <footer class="main-footer no-print">
        <div class="pull-right hidden-xs">
            <b>Version</b> 3.1.4
        </div>
        <strong>Copyright &copy; 2015-2016 <a href="http://www.tpson.cn/" target="_blank">拓深科技</a>.</strong> All rights reserved.
    </footer>
</div>

<script src="assets/plugins/jQuery/jQuery-2.1.4.min.js"></script>
<script src="assets/bootstrap/js/bootstrap.min.js"></script>
<script src="assets/plugins/input-mask/jquery.inputmask.js"></script>
<script src="assets/plugins/input-mask/jquery.inputmask.date.extensions.js"></script>
<script src="assets/plugins/input-mask/jquery.inputmask.extensions.js"></script>
<script src="assets/moment.js"></script>
<script src="assets/plugins/daterangepicker/daterangepicker.js"></script>
<script src="assets/DataTables-1.10.11/media/js/jquery.dataTables.min.js"></script>
<script src="assets/DataTables-1.10.11/media/js/dataTables.bootstrap.min.js"></script>
<script src="assets/plugins/slimScroll/jquery.slimscroll.min.js"></script>
<script src="assets/plugins/fastclick/fastclick.min.js"></script>
<script src="assets/layer-v2.2/layer/layer.js"></script>
<script src="assets/AdminLTE/dist/js/app.min.js"></script>
<script src="assets/AdminLTE/dist/js/demo.js"></script>
<script src="assets/cxSelect-master/js/jquery.cxselect.min.js"></script>
<script src="assets/ipicture/js/jquery.ipicture_location.js"></script>
<script src="js/alert_check.js"></script>
<script>
    var server;
    var tableDataArr = [];
    var monitorTable;
    var alertType = getParam('alertType');
    $(function () {
        var path = document.location.pathname;
        var href = document.location.href;
        if(path =='/'){
            var index = href.indexOf(path,href.indexOf(path)+2);
        }else {
            var index = href.indexOf(path);
        }
        var localPath = href.substring(0,index);
        var localName = path.substring(0,path.substr(1).indexOf('/')+1);
        server = localPath + localName;
        socketInit(server.substring(5));
        $('#reservation').daterangepicker();
        initMonitorTable();
        if(alertType==1){
            ReadTable1();
        }else if(alertType==2){
            ReadTable2();
        }else {
            ReadTable();
        }
        window.onload = checkAlert(server);
    });
    function ReadTable() {
        $.ajax({
            url:server+"/xk/alarm/getAll" ,
            async:false,
            success:function (data_in) {
                var json = JSON.parse(data_in);
                if(json.length == 0){
                    layer.alert('没有数据！',{
                        closeBtn: 0
                    });
                }else{
                    var monitorDataShow = [];
                    for(var i in json.data){
                        var datas = json.data;
                        var obj = {
                            id: datas[i].id,
                            name:datas[i].monitor_name,
                            time:formatDate(datas[i].alarm_time),
                            confirm_time:formatDate(datas[i].confirm_time),
                            device_name:datas[i].device_name,
                            location:datas[i].geo_1_name+'_'+datas[i].geo_2_name+'_'+datas[i].geo_3_name,
                            sensor_name:datas[i].sensor_name,
                            addr:datas[i].dev_addr,
                            status:datas[i].confirm_status,
                        };
                        monitorDataShow.push(obj);
                    }
                    monitorTable.clear().draw();
                    monitorTable.rows.add(monitorDataShow).draw();
                }
            }
        });
    }
    function ReadTable1() {
        $.ajax({
            url:server+"/xk/alarm/getOneMonthAll" ,
            async:false,
            success:function (data_in) {
                var json = JSON.parse(data_in);
                if(json.length == 0){
                    layer.alert('没有数据！',{
                        closeBtn: 0
                    });
                }else{
                    var monitorDataShow = [];
                    for(var i in json.data){
                        var datas = json.data;
                        var obj = {
                            id: datas[i].id,
                            name:datas[i].monitor_name,
                            time:formatDate(datas[i].alarm_time),
                            confirm_time:formatDate(datas[i].confirm_time),
                            device_name:datas[i].device_name,
                            location:datas[i].geo_1_name+'_'+datas[i].geo_2_name+'_'+datas[i].geo_3_name,
                            sensor_name:datas[i].sensor_name,
                            addr:datas[i].dev_addr,
                            status:datas[i].confirm_status,
                        };
                        monitorDataShow.push(obj);
                    }
                    monitorTable.clear().draw();
                    monitorTable.rows.add(monitorDataShow).draw();
                }
            }
        });
    }
    function ReadTable2() {
        $.ajax({
            url:server+"/xk/alarm/getOneMonthIgnore" ,
            async:false,
            success:function (data_in) {
                var json = JSON.parse(data_in);
                if(json.length == 0){
                    layer.alert('没有数据！',{
                        closeBtn: 0
                    });
                }else{
                    var monitorDataShow = [];
                    for(var i in json.data){
                        var datas = json.data;
                        var obj = {
                            id: datas[i].id,
                            name:datas[i].monitor_name,
                            time:formatDate(datas[i].alarm_time),
                            confirm_time:formatDate(datas[i].confirm_time),
                            device_name:datas[i].device_name,
                            location:datas[i].geo_1_name+'_'+datas[i].geo_2_name+'_'+datas[i].geo_3_name,
                            sensor_name:datas[i].sensor_name,
                            addr:datas[i].dev_addr,
                            status:datas[i].confirm_status,
                        };
                        monitorDataShow.push(obj);
                    }
                    monitorTable.clear().draw();
                    monitorTable.rows.add(monitorDataShow).draw();
                }
            }
        });
    }
    function initMonitorTable() {
        monitorTable = $('#alert_table').DataTable({
            paging: true,
            columns:[
                {data: "id"},
                {data: "name"},
                {data: "time"},
                {data: "device_name"},
                {data: "location"},
                {data: "sensor_name"},
                {data: "addr"},
                {data: null,"width":"100px"}
            ],
            columnDefs:[{
                targets:7,
                render: function (data, type, row, meta) {
                    if(row.status == 1){
                        return'<button type="button"class="btn btn-success"title="确认时间'+row.confirm_time+'">已确认</button>';
                    }else if(row.status == 3){
                        return'<button type="button"class="btn btn-warning"title="确认误报时间'+row.confirm_time+'">误&#12288报</button>';
                    }else {
                        return'<button type="button"class="btn btn-danger" onclick=editRecord('+row.id+')  title="忽略时间'+row.confirm_time+'">未确认</button>';
                    }
                }
            }],

            language:{
                "sProcessing":   "处理中...",
                "sLengthMenu":   "显示 _MENU_ 项结果",
                "sZeroRecords":  "没有匹配结果",
                "sInfo":         "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
                "sInfoEmpty":    "显示第 0 至 0 项结果，共 0 项",
                "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
                "sInfoPostFix":  "",
                "sSearch":       "搜索:",
                "sUrl":          "",
                "sEmptyTable":     "表中数据为空。",
                "sLoadingRecords": "载入中...",
                "sInfoThousands":  ",",
                "oPaginate": {
                    "sFirst":    "首页",
                    "sPrevious": "上页",
                    "sNext":     "下页",
                    "sLast":     "末页"
                },
                "oAria": {
                    "sSortAscending":  ": 以升序排列此列",
                    "sSortDescending": ": 以降序排列此列"
                }
            }
        });
    };
    function editRecord(id){
        layer.open({
            type:1,
            area: ['300px','150px'],
            title: '报警状态更改',
            skin:'layui-layer-lan',
            content: '你确定要更改此条报警记录状态？',
            btn:['确认报警','误报','取消'],
            btn1:function (index, layero) {
                layer.confirm("状态更改将不可恢复！",{
                    title:"确定报警",
                    skin:"layui_layer_molv",
                    btn:['确认报警','取消']
                },function(){
                    $.ajax({
                        url:server + '/xk/alarm/alarmUpdate?alarm_id='+ id,
                        success:function (data) {
                            ReadTable();
                            layer.closeAll();
                        }
                    });
                },function(){})
            },
            btn2: function (index, layero) {
                layer.confirm("状态更改将不可恢复！",{
                    title:"确定误报",
                    skin:"layui_layer_molv",
                    btn:['确认误报','取消']
                },function(){
                    $.ajax({
                        url:server + '/xk/alarm/alarmUpdate2?alarm_id='+ id,
                        success:function (data) {
                            ReadTable();
                            layer.closeAll();
                        }
                    });
                },function(){})
            },
            btn3:function (index, layero) {
                layer.close(index);
            }
            ,success: function(layero){
            }
        })
    }
    function   formatDate(time)   {
        if(!time){time = 0;}
        time = time*1000;
        var DD = new Date(time);
        var year=DD.getFullYear();
        var month=DD.getMonth()+1;
        month = month<10?'0'+month:month;
        var date=DD.getDate();
        date = date<10?'0'+date:date;
        var hours=DD.getHours();
        hours = hours<10?'0'+hours:hours;
        var minutes=DD.getMinutes();
        minutes = minutes<10?'0'+minutes:minutes;
        var seconds=DD.getSeconds();
        seconds = seconds<10?'0'+seconds:seconds;
        return   year+"/"+month+"/"+date+' '+hours+':'+minutes+":"+seconds;
    }
    function getParam(paramName) {
        paramValue = "";
        isFound = false;
        if (this.location.search.indexOf("?") == 0 && this.location.search.indexOf("=") > 1) {
            arrSource = decodeURI(this.location.search).substring(1, this.location.search.length).split("&");
            i = 0;
            while (i < arrSource.length && !isFound) {
                if (arrSource[i].indexOf("=") > 0) {
                    if (arrSource[i].split("=")[0].toLowerCase() == paramName.toLowerCase()) {
                        paramValue = arrSource[i].split("=")[1];
                        isFound = true;
                    }
                }
                i++;
            }
        }
        return paramValue;
    }
</script>
</body>
</html>